home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Mac C Primer V1 CW9 / 68K and PPC Projects (CW9) / 3.3 - ShowPICT / ShowPICT.c < prev    next >
C/C++ Source or Header  |  1996-05-28  |  2KB  |  109 lines

  1. /********************************************************/
  2. /*                                                        */
  3. /*  ShowPICT Code from Chapter Three of                    */
  4. /*                                                        */
  5. /*    *** The Macintosh Programming Primer, 2nd Ed. ***    */
  6. /*                                                      */
  7. /*    Copyright 1992, Dave Mark and Cartwright Reed       */
  8. /*                                                        */
  9. /********************************************************/
  10.  
  11. #define kBaseResID            128
  12. #define    kMoveToFront        (WindowPtr)-1L
  13.  
  14.  
  15. /***************/
  16. /*  Functions  */
  17. /***************/
  18.  
  19. void    ToolBoxInit( void );
  20. void    WindowInit( void );
  21. void    DrawMyPicture( void );
  22. void    CenterPict( PicHandle picture, Rect *destRectPtr );
  23.  
  24.  
  25. /****************** main ***************************/
  26.  
  27. void    main( void )
  28. {
  29.     ToolBoxInit();
  30.     WindowInit();
  31.     
  32.     DrawMyPicture();
  33.     
  34.     while ( !Button() ) ;
  35. }
  36.  
  37.  
  38. /****************** ToolBoxInit *********************/
  39.  
  40. void    ToolBoxInit( void )
  41. {
  42.     InitGraf( &qd.thePort );
  43.     InitFonts();
  44.     InitWindows();
  45.     InitMenus();
  46.     TEInit();
  47.     InitDialogs( 0L );
  48.     InitCursor();
  49. }
  50.  
  51.  
  52. /****************** WindowInit ***********************/
  53.  
  54. void    WindowInit( void )
  55. {
  56.     WindowPtr    window;
  57.     
  58.     window = GetNewWindow( kBaseResID, nil, kMoveToFront );
  59.     
  60.     if ( window == nil )
  61.     {
  62.         SysBeep( 10 );    /*  Couldn't load the WIND resource!!!  */
  63.         ExitToShell();
  64.     }
  65.     
  66.     ShowWindow( window );
  67.     SetPort( window );
  68. }
  69.  
  70.  
  71. /****************** DrawMyPicture ********************/
  72.  
  73. void    DrawMyPicture( void )
  74. {
  75.     Rect        pictureRect;
  76.     WindowPtr    window;
  77.     PicHandle    picture;
  78.     
  79.     window = FrontWindow();
  80.     
  81.     pictureRect = window->portRect;
  82.     
  83.     picture = GetPicture( kBaseResID );
  84.     
  85.     if ( picture == nil )
  86.     {
  87.         SysBeep( 10 );    /*  Couldn't load the PICT resource!!!  */
  88.         ExitToShell();
  89.     }
  90.     
  91.     CenterPict( picture, &pictureRect );
  92.     DrawPicture( picture, &pictureRect );
  93. }
  94.  
  95.  
  96. /****************** CenterPict ********************/
  97.  
  98. void    CenterPict( PicHandle picture, Rect *destRectPtr )
  99. {
  100.     Rect    windRect, pictRect;
  101.     
  102.     windRect = *destRectPtr;
  103.     pictRect = (**( picture )).picFrame;
  104.     OffsetRect( &pictRect, windRect.left - pictRect.left,
  105.                            windRect.top     - pictRect.top);
  106.     OffsetRect( &pictRect,(windRect.right - pictRect.right)/2,
  107.                           (windRect.bottom - pictRect.bottom)/2);
  108.     *destRectPtr = pictRect;
  109. }